<?php

class Dispatcher {

	var $module = 'index';

	var $moduleDir = 'app';

	var $prefix = 'Module';

	function Dispatcher() {
		if(isset($_GET['module']))
			$this->module = $_GET['module'];

		$moduleFile = ROOT . $this->moduleDir . '/' . $this->module . '.php';
		if(!preg_match("/^[\w]+$/", $this->module) or 
			!is_readable($moduleFile)) 
			trigger_error("Module ID '$this->module' is invalid.", E_USER_ERROR);

		include $moduleFile;
		$moduleClazz = $this->prefix . ucfirst($this->module);
		$app = new $moduleClazz($this->module);
	}
}

?>
